'/
' Fetherquest Online
' 
' =========================================================================
' 
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
' 
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
' 
' You should have received a copy of the GNU General Public License
' along with this program.  If not, see <http://www.gnu.org/licenses/>.
'/

superstrict

framework BRL.Blitz

import BRL.Threads

import "../../lib/RabMT/RabMT.bmx"
import "../../lib/errorutil/errorutil.bmx"
import "../../framework/exit/exit.c"

import "Master.bmx"

include "../../framework/exit/exit.bmx"

execute();

'// ----------------------------------------------------------------------------------------------------------------
'// Main. All it does is launch the master thread, and return an error message when shutting down, if the master
'// thread function returns anything other than 'null'. 
'// ----------------------------------------------------------------------------------------------------------------
function main:int()

	'// Set application title.
	appTitle = sMaster.GAME_TITLE;
	
	'// Launch the master thread.
	if (not sMaster.run(null)) ..
		return 1;
	'if (not RabMT.launchThread("master", sMaster.run, null)) ..
	'	return 1;
	
	'// Wait for the master thread to finish..
	'local error:string = string(waitThread(RabMT.getThread("master")));
	
	'// If an error occured, terminate the program with an errorcode and notify the user
	'// of the error message that was returned from the master thread.
	'if (error) then
	
	'	errorutil.error(error);
	'	return 1;
	
	'end if
	
	'// Return a successful termination of the program.
	return 0;

end function
